﻿using System;
/*Write a program that reads two integer numbers N and K and an array of N elements from the console. Find in
 * the array those K elements that have maximal sum.
*/

    class MaxSumNK
    {
        static void Main()
        {
            Console.WriteLine("Write the first number:");
            int N = int.Parse(Console.ReadLine());

            Console.WriteLine("Write the second number:");
            int K = int.Parse(Console.ReadLine());

            int[] array = new int[N];
            Console.WriteLine("Write the numbers in the array:");
            for (int i = 0; i < array.Length; i++)
            {
                array[i] = int.Parse(Console.ReadLine());
            }

            Console.WriteLine("The sorted array is:");
            Array.Sort(array);
            foreach (int i in array) 
            Console.Write(i + " ");

            Console.WriteLine();

            Console.WriteLine("The numbers are:");
            for (int i = array.Length-K; i <array.Length; i++)
            {                
                Console.Write(array[i]);                
            }
            
        }
    }

